﻿$(function() {
    $.datepicker.setDefaults($.extend({ showMonthAfterYear: false }, $.datepicker.regional['zh-CN']));
    $("#date").datepicker({ changeMonth: true, changeYear: true });
});
$(function() {
    $("#DIALOG").dialog({
        autoOpen: false,
        bgiframe: true,
        modal: true,
		show:'slide'
    });
});

function gettypevalue() {
    function check(index) {
        for (var i = 1; i <= 5; ++i)
            if (_$("ID_INDICATOR_"+index+"_" + i).checked) return i;
        return -1;
    }
    var types = [];
    for (var i = 1; i <= 5; ++i) {
        types.push(check(i));
    }
    return types;
}
function AddHistory(){
    var surl="/pages/alpha/XiaoChuanHistory/XiaoChuanUpdate.aspx?type=0";
    var date = _$("date").value;
    var typevalues = gettypevalue();
    var index = typevalues.find(-1);
   
    if (index != null) {
		$.prompt("请选择第" + (index+1) + "项", { buttons: { 关闭: true }, focus: 1});
        return;
    }
    var value = typevalues.join(',');
    surl = surl+"&&date="+date.escUrl()+"&&value="+value ;
    function OnSuc(xmlDoc)
    {
        $.prompt("操作成功！", { buttons: { 关闭: true }, focus: 1, callback:function(v,m,f){
			window.location.href = window.location.href;
		}});
        
    }
    function OnFail(xmlDoc)
    {
        var result = xmlDoc.getElementsByTagName("result")[0];
        retCode = result.getAttribute("code");
        retMsg = result.getAttribute("msg");
        if ( -200 == retCode) {
			$.prompt(retMsg, { buttons: { 是: true, 否: false }, focus: 1 , callback:function(v, m, f){
			if(v){
				surl += "&force=1";
				getResultXml(surl,OnSuc,OnFail,OnError); 
			}
			}});
		}else if ( -103 == retCode){
			$.prompt(retMsg+"现在去修改发病日期吗？", { buttons: { 是: true, 否: false }, focus: 1 , callback:function(v, m, f){
				if(v){
					parent.location.href = "../DiseaseHistory/Index.aspx";
				}
			}});
		}
        else
        {
			$.prompt(retMsg, { buttons: { 关闭: true}, focus: 1 });
        }
    }
    function OnError()
    {
		$.prompt("操作失败，请稍后再试", { buttons: { 关闭: true}, focus: 1 });
    }
    getResultXml(surl,OnSuc,OnFail,OnError);
}
function DelHistory(id) {
	function delHistory(){
		function OnSuc(xmlDoc)
		{   
			$.prompt("操作成功！", { buttons: { "关闭": true}, focus: 1, callback:function(v,m,f){
				window.location.href = window.location.href ;  
			}});
			     
		}
		function OnFail(xmlDoc)
		{
			var result = xmlDoc.getElementsByTagName("result")[0];
			retCode = result.getAttribute("code");
			retMsg = result.getAttribute("msg");
			$.prompt(retMsg, { buttons: { 是: true, 否:false}, focus: 1});
		}
		var surl = "/pages/alpha/XiaoChuanHistory/XiaoChuanUpdate.aspx?type=2&id="+id;
		getResultXml(surl,OnSuc,OnFail,function(){$.prompt("操作失败，请稍后再试！", { buttons: { 是: true, 否:false}, focus: 1})});   
	}
	$.prompt("你确定删除吗？", { buttons: { 是: true, 否:false}, focus: 1 , callback:function(v, m, f){
		if(v){
			delHistory();
		}
	}});
}
function UpdateHistory(id){
	var iframe = $('#DIALOG iframe').get(0);
	var src = "HistoryEdit.aspx?id="+id;
    if (iframe.src.toLowerCase().indexOf(src) < 0) {
		iframe.src = src;
	}
	setDialogParam(iframe, 710, 400, $('#DIALOG'), 750, 440, '修改哮喘记录');
	$('#DIALOG').dialog('open');
}